package com.yuanheng100.ems4j.mapper;

import com.yuanheng100.ems4j.model.Ems4jDingTalk;
import com.yuanheng100.ems4j.model.Ems4jPage;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

public interface Ems4jDingTalkMapper
{

    @Insert({
            "INSERT INTO ems4j_dingtalk (dingId, msgtype, ",
            "sender, cid, content, ",
            "resultCode, sendTime, ",
            "title, touser, toparty, ",
            "media_id)",
            "VALUES (#{dingId,jdbcType=INTEGER}, #{msgtype,jdbcType=VARCHAR}, ",
            "#{sender,jdbcType=VARCHAR}, #{cid,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, ",
            "#{resultCode,jdbcType=SMALLINT}, #{sendTime,jdbcType=TIMESTAMP}, ",
            "#{title,jdbcType=VARCHAR}, #{touser,jdbcType=VARCHAR}, #{toparty,jdbcType=VARCHAR}, ",
            "#{media_id,jdbcType=INTEGER})"
    })
    int insert(Ems4jDingTalk record);

    @Select({
            "SELECT",
            "dingId, msgtype, sender, cid, content, resultCode, sendTime, title, touser, ",
            "toparty, media_id",
            "FROM ems4j_dingtalk",
            "WHERE dingId = #{dingId,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column = "dingId", property = "dingId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "msgtype", property = "msgtype", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sender", property = "sender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "cid", property = "cid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "resultCode", property = "resultCode", jdbcType = JdbcType.SMALLINT),
            @Result(column = "sendTime", property = "sendTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "touser", property = "touser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "toparty", property = "toparty", jdbcType = JdbcType.VARCHAR),
            @Result(column = "media_id", property = "media_id", jdbcType = JdbcType.INTEGER)
    })
    Ems4jDingTalk selectByPrimaryKey(Integer dingId);

    @Update({
            "UPDATE ems4j_dingtalk",
            "SET msgtype = #{msgtype,jdbcType=VARCHAR},",
            "sender = #{sender,jdbcType=VARCHAR},",
            "cid = #{cid,jdbcType=VARCHAR},",
            "content = #{content,jdbcType=VARCHAR},",
            "resultCode = #{resultCode,jdbcType=SMALLINT},",
            "sendTime = #{sendTime,jdbcType=TIMESTAMP},",
            "title = #{title,jdbcType=VARCHAR},",
            "touser = #{touser,jdbcType=VARCHAR},",
            "toparty = #{toparty,jdbcType=VARCHAR},",
            "media_id = #{media_id,jdbcType=INTEGER}",
            "WHERE dingId = #{dingId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Ems4jDingTalk record);

    @SelectProvider(type = Ems4jDingTalkSqlProvider.class, method = "selectCountByCondition")
    Long selectCountByCondition(Map<String, Object> conditions);

    @SelectProvider(type = Ems4jDingTalkSqlProvider.class, method = "selectListByCondition")
    List<Ems4jDingTalk> selectListByCondition(@Param("conditions") Map<String, Object> conditions, @Param("page") Ems4jPage<Ems4jDingTalk> page);
}